package com.hmall.search.filter;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author Azer
 * @LOVE,,,
 * @Date 2021/11/8 15:24
 */
@Component
public class ItemInterceptor implements HandlerInterceptor {

    //定义一个ThreadLocal
    private static  final ThreadLocal<Long> thread=new ThreadLocal<>();

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String userId = request.getHeader("authorization");
        thread.set(Long.valueOf(userId));

        return true;
    }
}
